{extend name="./base" /}

{block name="body"}
<form class="layui-form model-form" id="thisForm">
	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">活动名称</label>
		<div class="layui-input-block">
			<input name="form[title]" class="layui-input" lay-verify="required" value="{$data['title'] ?? ''}"/>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">开奖机制</label>
		<div class="layui-input-inline">
			<select name="form[cycle_type]">
				<option value="0">--请选择--</option>
				{foreach $types as $key=>$type}
					<option value="{$key}" {if @$data[cycle_type] == $key}selected{/if}>{$type}</option>
				{/foreach}
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">活动日期</label>
		<div class="layui-inline" id="expired">
			<div class="layui-input-inline">
				<input type="text" name="form[start_time]" value="{$data['start_time'] ?? ''}" autocomplete="off" id="start_time" class="layui-input" placeholder="开始日期">
			</div>
			<div class="layui-form-mid">-</div>
			<div class="layui-input-inline">
				<input type="text" name="form[end_time]" value="{$data['end_time'] ?? ''}" autocomplete="off" id="end_time" class="layui-input" placeholder="结束日期">
			</div>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">最低消耗分</label>
		<div class="layui-input-block">
			<input name="form[lowest]" class="layui-input" lay-verify="required" value="{$data['lowest'] ?? ''}"/>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">奖品名称</label>
		<div class="layui-input-block">
			<input name="form[prize_name]" class="layui-input" lay-verify="required" value="{$data['prize_name'] ?? ''}"/>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">奖品数量</label>
		<div class="layui-input-block">
			<input name="form[prize_num]" class="layui-input" lay-verify="required" value="{$data['prize_num'] ?? ''}"/>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">领奖过期天数</label>
		<div class="layui-input-block">
			<input name="form[prize_expire_days]" class="layui-input" value="{$data['prize_expire_days'] ?? ''}"/>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden" name="form[id]" value="{$data['id'] ?? 0}">
			<button class="layui-btn" lay-filter="formSubmit" lay-submit>保存</button>
			<button class="layui-btn layui-btn-primary" type="reset" >重置</button>
		</div>
	</div>
</form>
{/block}

{block name="script"}
<script>
	layui.use(['layer', 'form', 'table', 'laydate'], function () {
		var $ = layui.jquery, form= layui.form, laydate = layui.laydate;

		laydate.render({
			elem: '#expired'
			,type: 'datetime'
			,range: ['#start_time', '#end_time']
		});

		// 表单提交
		form.on('submit(formSubmit)', function (data) {
			let formData = data.field;
			$.post('/admin/activity/edit', formData, function(res){
				window.location.href = '/admin/activity/index';
			})
			return false;
		});
	})
</script>
{/block}